import java.util.*;

/**
 * This class represents node (computer) in a computer network. Each node
 * has a set of properties describing it and a list of other nodes it can access
 * over the network. Nodes are differentiated in a network by the IDs, which
 * must be set when the Node is instantiated.
 * 
 * XXX Should be a DefaultGraphCell
 * 
 * Original Author: Aaron A. Lovato
 * @author Aaron A. Lovato
 */


public class Node
{
    // This node's ID in the network. 
    private int id;
    
    private boolean compromised;
    
    // This node's hostname for displaying on the screen
    private String hostname;
  
    // List of nodes accessible from this node
    private Vector<Node> neighbors;
    
    private String OS;

    private boolean high_value;

    Random rand = new Random();
    
    public Node(int id, String name, String OS, boolean hv)
    {
        this.compromised = false;
        this.id = id;
        this.hostname = name;
        this.OS = OS;
        this.high_value = hv;
        this.neighbors = new Vector<Node>();
    }
    
    public void addNeighbor(Node n)
    {
        this.neighbors.add(n);
    }
    
    public Vector<Node> getNeighbors()
    {
        return neighbors;
    }

    public int getID()
    {
        return this.id;
    }

    public String getName()
    {
        return this.hostname;
    }
    
    public String getOS()
    {
        return this.OS;
    }

    public boolean isCompromised()
    {
        return this.compromised;
    }

    public boolean isHighValue()
    {
        return this.high_value;
    }

    public boolean isNeighborsAllCompromised()
    {
        for (int i = 0; i < this.neighbors.size(); i++)
        {
            if (!this.neighbors.get(i).isCompromised())
                return false;
        }
        return true;
    }

    public Node getRandomNeighbor()
    {
        while(true)
        {
            Node n = this.neighbors.get(rand.nextInt(this.neighbors.size()));
            if(!n.isCompromised())
            {
            return n;
            }
        }
    }

    public void reset()
    {
        this.compromised = false;
    }

}